#include"search.hpp"
#include<iostream>
#include<vector>
#include"cpp-httplib/httplib.h"


const std::string input = "data/output/raw.txt";
const std::string root_path = "./wwwroot";
int main()
{
    ns_search::Searcher search;
    search.InitSearch(input);

    httplib::Server svr;
    svr.set_base_dir(root_path.c_str());
    svr.Get("/s",[&search](const httplib::Request &req,httplib::Response & resp)
    {
        if(!req.has_param("word"))
        {
            resp.set_content("必须要有搜索关键字!", "text/plain; charset=utf-8");
            return;
        }
        std::string word = req.get_param_value("word");
        std::string json_string;
        search.search(word,&json_string);
        resp.set_content(json_string,"application/json");
    });
    svr.listen("0.0.0.0",8081);
    return 0;
}